/**
 * Created by Administrator on 2018-09-05.
 * 停机位配置
 */


define(function (require,exports,module) {
    var sTpl = require("./gpConfig.html");
    require("./gpConfig.css")

    var VueComponent = Vue.extend({
        template: sTpl
        ,methods:{
            findAllGp:function() {
                var $this = this;
                axios.get(basepath+"/api/sysSetting/findGp"
                ).then(function (response) {
                    $this.tableData=response.data;
                });
            },

            addGp:function(){
                this.addGpData={
                    gpName:'',
                    gpNum:'',
                    gpType:'',
                    gpState:'',
                    apron:"",
                    px:'',
                    py:''
                };
                this.tl='机位添加'
                this.$refs.baseTable.dialogFormVisible = true;
                this.title='添加成功';

            },
            clear:function(){
                this.$refs.baseTable.dialogFormVisible = false;

            },
            saveClick:function () {
                var $this = this;
                this.$refs.addGpData.validate(function(validate){
                    if(validate){
                        axios.post(basepath+'/api/sysSetting/saveGp',$this.addGpData
                        )
                            .then(function (response) {
                                $this.$notify({
                                    title: $this.title,
                                    message: $this.title
                                });

                                $this.$refs.baseTable.dialogFormVisible = false;
                                $this.findAllGp();
                            });
                    }
                });

            },
            editGp:function (scope) {
                this.tl="机位修改"
                this.$refs.baseTable.dialogFormVisible = true;
                this.addGpData=JSON.parse(JSON.stringify(scope.row)) ;
                this.title='修改成功';
            },
            delectGp:function(scope){
                var $this = this ;
                this.$confirm('确定删除？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'success'
                }).then(function() {
                    axios.post(basepath+'/api/sysSetting/delectGp',scope.row)
                        .then(function (response) {
                            $this.$notify({
                                title: '已删除',
                                message: '已删除'
                            });

                            $this.findAllGp();
                        });
                })

            }
        },
        mounted:function() {

        }
        ,data:function(){
            return {

                gpStateTy:[{
                    value:'可用',
                    label:'可用'
                },{
                    value:'不可用',
                    label:'不可用'
                }],
                gpTypeTy:
                    [{
                        value:'小型',
                        label:'小型'
                    },{
                        value:'中型',
                        label:'中型'
                    },{
                        value:'大型',
                        label:'大型'
                    }],
                tl:'',
                title:'',
                dialogFormVisible: false,
                addGpData:{
                    gpName:'',
                    gpNum:'',
                    gpType:'',
                    gpState:'',
                    px:'',
                    py:''
                },
                tableData: {}
            }
        },
        created:function (){
            this.findAllGp();

        },
        activated:function () {
            messages.$emit('change','停机位配置');
        }
    });
    module.exports = VueComponent;
})
